From b93e7f7e8b78ca1ca3bb00f88f618a6d376c1b00 Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Tue, 17 May 2005 10:50:52 +0000 Subject: [PATCH] bitkeeper revision 1.1426.1.1 (4289cc8cPUM98bLJs4TV93NHY9LOKg) Many files: Make interface to network/block scripts consistent: - output on stdout is returned to the script caller - output on stderr is logged at the error level, messages with a '-' prefix are logged at the debug level and messages with a '*' prefix are logged at the info level. Signed-off-by: Christian Limpach --- tools/examples/block-enbd | 4 ++-- tools/examples/block-file | 4 ++-- tools/examples/network | 6 +++--- tools/examples/network-nat | 6 +++--- tools/examples/vif-bridge | 6 +++--- tools/examples/vif-nat | 6 +++--- tools/examples/vif-route | 6 +++--- tools/python/xen/util/process.py | 16 +++++++++++----- tools/python/xen/xend/Blkctl.py | 9 ++++----- tools/python/xen/xend/Vifctl.py | 9 ++++++--- 10 files changed, 40 insertions(+), 32 deletions(-) diff --git a/tools/examples/block-enbd b/tools/examples/block-enbd index cfae6288b2..a8fa108f0d 100755 --- a/tools/examples/block-enbd +++ b/tools/examples/block-enbd @@ -27,7 +27,7 @@ case $1 in ;; *) - echo 'Unknown command: ' $1 - echo 'Valid commands are: bind, unbind' + echo 'Unknown command: ' $1 >&2 + echo 'Valid commands are: bind, unbind' >&2 exit 1 esac diff --git a/tools/examples/block-file b/tools/examples/block-file index 362b1faee5..a1612b6d47 100755 --- a/tools/examples/block-file +++ b/tools/examples/block-file @@ -25,7 +25,7 @@ case $1 in ;; *) - echo 'Unknown command: ' $1 - echo 'Valid commands are: bind, unbind' + echo 'Unknown command: ' $1 >&2 + echo 'Valid commands are: bind, unbind' >&2 exit 1 esac diff --git a/tools/examples/network b/tools/examples/network index 12ff1c5eee..47daae95b0 100755 --- a/tools/examples/network +++ b/tools/examples/network @@ -53,7 +53,7 @@ bridge=${bridge:-xen-br0} netdev=${netdev:-eth0} antispoof=${antispoof:-yes} -echo "network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" +echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2 # Usage: transfer_addrs src dst # Copy all IP addresses (including aliases) from device $src to device $dst. @@ -232,7 +232,7 @@ case ${OP} in ;; *) - echo 'Unknown command: ' ${OP} - echo 'Valid commands are: start, stop, status' + echo 'Unknown command: ' ${OP} >&2 + echo 'Valid commands are: start, stop, status' >&2 exit 1 esac diff --git a/tools/examples/network-nat b/tools/examples/network-nat index e0050a4e72..0d6460f308 100644 --- a/tools/examples/network-nat +++ b/tools/examples/network-nat @@ -32,7 +32,7 @@ netdev=${netdev:-eth0} # antispoofing not yet implemented antispoof=${antispoof:-no} -echo "network-nat $OP netdev=$netdev antispoof=$antispoof" +echo "*network-nat $OP netdev=$netdev antispoof=$antispoof" >&2 op_start() { @@ -71,7 +71,7 @@ case ${OP} in ;; *) - echo 'Unknown command: ' ${OP} - echo 'Valid commands are: start, stop, status' + echo 'Unknown command: ' ${OP} >&2 + echo 'Valid commands are: start, stop, status' >&2 exit 1 esac diff --git a/tools/examples/vif-bridge b/tools/examples/vif-bridge index 42bdf0e173..1c5bc161f9 100755 --- a/tools/examples/vif-bridge +++ b/tools/examples/vif-bridge @@ -34,7 +34,7 @@ # Exit if anything goes wrong set -e -echo "vif-bridge $*" +echo "*vif-bridge $*" >&2 # Operation name. OP=$1 @@ -63,8 +63,8 @@ case $OP in iptcmd='-D' ;; *) - echo 'Invalid command: ' $OP - echo 'Valid commands are: up, down' + echo 'Invalid command: ' $OP >&2 + echo 'Valid commands are: up, down' >&2 exit 1 ;; esac diff --git a/tools/examples/vif-nat b/tools/examples/vif-nat index 4b6d348dfa..00977f8819 100644 --- a/tools/examples/vif-nat +++ b/tools/examples/vif-nat @@ -23,7 +23,7 @@ # Exit if anything goes wrong set -e -echo "vif-nat $*" +echo "*vif-nat $*" >&2 # Operation name. OP=$1 @@ -56,8 +56,8 @@ case $OP in ipcmd='d' ;; *) - echo 'Invalid command: ' $OP - echo 'Valid commands are: up, down' + echo 'Invalid command: ' $OP >&2 + echo 'Valid commands are: up, down' >&2 exit 1 ;; esac diff --git a/tools/examples/vif-route b/tools/examples/vif-route index b15aea1e5c..e2ff8b0f19 100755 --- a/tools/examples/vif-route +++ b/tools/examples/vif-route @@ -24,7 +24,7 @@ # Exit if anything goes wrong set -e -echo "vif-route $*" +echo "*vif-route $*" >&2 # Operation name. OP=$1 @@ -57,8 +57,8 @@ case $OP in ipcmd='d' ;; *) - echo 'Invalid command: ' $OP - echo 'Valid commands are: up, down' + echo 'Invalid command: ' $OP >&2 + echo 'Valid commands are: up, down' >&2 exit 1 ;; esac diff --git a/tools/python/xen/util/process.py b/tools/python/xen/util/process.py index f6aac50f5b..07bc73b505 100644 --- a/tools/python/xen/util/process.py +++ b/tools/python/xen/util/process.py @@ -4,10 +4,11 @@ import popen2 import select +import string from xen.xend.XendLogging import log -def system(cmd): +def runscript(cmd): # split after first space, then grab last component of path cmdname = "[%s] " % cmd.split()[0].split('/')[-1] # run command and grab stdin, stdout and stderr @@ -18,14 +19,19 @@ def system(cmd): p = select.poll() p.register(cout) p.register(cerr) + stdout = "" while True: r = p.poll() for (fd, event) in r: if event == select.POLLHUP: - return + return stdout if fd == cout.fileno(): - l = cout.readline() - log.info(cmdname + l.rstrip()) + stdout = stdout + cout.readline() if fd == cerr.fileno(): l = cerr.readline() - log.error(cmdname + l.rstrip()) + if l[0] == '-': + log.debug(cmdname + l[1:].rstrip()) + elif l[0] == '*': + log.info(cmdname + l[1:].rstrip()) + else: + log.error(cmdname + l.rstrip()) diff --git a/tools/python/xen/xend/Blkctl.py b/tools/python/xen/xend/Blkctl.py index d90c7ce51d..0b46f54079 100644 --- a/tools/python/xen/xend/Blkctl.py +++ b/tools/python/xen/xend/Blkctl.py @@ -4,6 +4,7 @@ import os import os.path import sys import string +import xen.util.process from xen.xend import XendRoot @@ -38,8 +39,6 @@ def block(op, type, dets, script=None): script = os.path.join(SCRIPT_DIR, script) args = [op] + string.split(dets, ':') args = ' '.join(args) - out = os.popen(script + ' ' + args) - - output = _readline(out) - out.close() - return string.rstrip(output) + ret = xen.util.process.runscript(script + ' ' + args) + if len(ret): + return ret.splitlines()[0] diff --git a/tools/python/xen/xend/Vifctl.py b/tools/python/xen/xend/Vifctl.py index d26f78d7a0..0bc58f4480 100644 --- a/tools/python/xen/xend/Vifctl.py +++ b/tools/python/xen/xend/Vifctl.py @@ -36,7 +36,9 @@ def network(op, script=None, bridge=None, antispoof=None): else: args.append("antispoof=no") args = ' '.join(args) - xen.util.process.system(script + ' ' + args) + ret = xen.util.process.runscript(script + ' ' + args) + if len(ret): + return ret.splitlines()[0] def set_vif_name(vif_old, vif_new): if vif_old == vif_new: @@ -81,5 +83,6 @@ def vifctl(op, vif=None, script=None, domain=None, mac=None, bridge=None, ipaddr ips = ' '.join(ipaddr) args.append("ip='%s'" % ips) args = ' '.join(args) - os.system(script + ' ' + args) - + ret = xen.util.process.runscript(script + ' ' + args) + if len(ret): + return ret.splitlines()[0] -- 2.30.2